<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="关联企业id" prop="enterprise.id">
                <!-- :rules="[
                  {required: true, message:'关联企业id不能为空', trigger:'blur'}
                 ]" -->
          <GridSelect
          :disabled="inputForm.enterpriseuser.id.length!=0"
            title="选择关联企业id"
            labelName = 'companyName'
            labelValue = 'id'
            :value = "inputForm.enterprise.id"
            :limit="1"
            @getValue='(value) => {inputForm.enterprise.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/list"
            entityBeanName="enterpriseInformation"
            queryEntityUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="关联企业用户" prop="enterpriseuser.id">
                <!-- :rules="[
                  {required: true, message:'关联企业用户不能为空', trigger:'blur'}
                 ]" -->
          <GridSelect
          :disabled="inputForm.enterprise.id.length!=0"
            title="选择关联企业用户"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.enterpriseuser.id"
            :limit="1"
            @getValue='(value) => {inputForm.enterpriseuser.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriseuserinformation/enterpriseUserInformation/list"
            entityBeanName="enterpriseUserInformation"
            queryEntityUrl="/dlyrl/hr/enterpriseuserinformation/enterpriseUserInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务标题" prop="taskTitle"
                :rules="[
                  {required: true, message:'任务标题不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.taskTitle" placeholder="请填写任务标题"   ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务编号" prop="taskNumber"
                :rules="[
                  {required: true, message:'任务编号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.taskNumber" placeholder="请填写任务编号"   :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务文字描述" prop="taskContent"
                :rules="[
                 ]">
              <el-input v-model="inputForm.taskContent" placeholder="请填写任务文字描述"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="佣金" prop="commission"
                :rules="[
                 ]">
              <el-input v-model="inputForm.commission" placeholder="请填写佣金"   :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="总佣金" prop="totalCommission"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalCommission" placeholder="请填写总佣金"  :disabled="disFalse" ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余佣金" prop="surplusCommission"
                :rules="[
                 ]">
              <el-input v-model="inputForm.surplusCommission" placeholder="请填写剩余佣金"  :disabled="disFalse" ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="接收组" prop="receiveGroup.id"
                :rules="[
                  {required: true, message:'接收组不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择接收组"
            labelName = 'groupName'
            labelValue = 'id'
            :value = "inputForm.receiveGroup.id"
            :limit="1"
            @getValue='(value) => {inputForm.receiveGroup.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'groupName',
              label: '组名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'groupName',
              label: '组名称'
            }
            ]"
            dataListUrl="/lhyg/lgy/pcusergroup/lhygPcUserGroup/list"
            entityBeanName="lhygPcUserGroup"
            queryEntityUrl="/lhyg/lgy/pcusergroup/lhygPcUserGroup/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="接收人" prop="receiveGroupuser.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择接收人"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.receiveGroupuser.id"
            :limit="1"
            @getValue='(value) => {inputForm.receiveGroupuser.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/list"
            entityBeanName="userInformation"
            queryEntityUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否完成" prop="isComplete"
                :rules="[
                 ]">
                <el-select v-model="inputForm.isComplete" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('is_complete')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="支付方式" prop="payment"
                :rules="[
                 ]">
                <el-select v-model="inputForm.payment" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('dealType_E')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审核状态" prop="auditStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.auditStatus" placeholder="请选择"  style="width: 100%;"   :disabled="statusFalse"> 
                          <el-option
                            v-for="item in $dictUtils.getDictList('audit_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预收服务费" prop="advanceReceivableServiceFee"
                :rules="[
                 ]">
              <el-input v-model="inputForm.advanceReceivableServiceFee" placeholder="请填写预收服务费"  :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预收税额" prop="advanceReceivableTaxForehead"
                :rules="[
                 ]">
              <el-input v-model="inputForm.advanceReceivableTaxForehead" placeholder="请填写预收税额" :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预收总额" prop="advanceReceivableRental"
                :rules="[
                 ]">
              <el-input v-model="inputForm.advanceReceivableRental" placeholder="请填写预收总额" :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余服务费" prop="residueServiceFee"
                :rules="[
                 ]">
              <el-input v-model="inputForm.residueServiceFee" placeholder="请填写剩余服务费"  :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余税额" prop="residueTaxForehead"
                :rules="[
                 ]">
              <el-input v-model="inputForm.residueTaxForehead" placeholder="请填写剩余税额"  :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余总额" prop="residueRental"
                :rules="[
                 ]">
              <el-input v-model="inputForm.residueRental" placeholder="请填写剩余总额"  :disabled="disFalse"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发票价税合计" prop="invoiceValoremTaxTotal"
                :rules="[
                 ]">
              <el-input v-model="inputForm.invoiceValoremTaxTotal" placeholder="请填写发票价税合计" :disabled="disFalse"  ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="线上订单号" prop="orderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.orderNumber" placeholder="请填写线上订单号"   :disabled="disFalse" ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务主图" prop="taskImg"
                :rules="[
                 ]">
              <el-upload ref="taskImg"
                    v-if="visible"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/lhyg/lgy/pctaskinformation/lhygPcTaskinformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file, fileList) => {$window.location.href = (file.response && file.response.url) || file.url}"
                    :on-success="(response, file, fileList) => {
                       inputForm.taskImg = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.taskImg = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="taskImgArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="上传支付凭证" prop="uploadPaymentVoucher"
                :rules="[
                 ]">
              <el-upload ref="uploadPaymentVoucher"
                    v-if="visible"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/lhyg/lgy/pctaskinformation/lhygPcTaskinformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file, fileList) => {$window.location.href = (file.response && file.response.url) || file.url}"
                    :on-success="(response, file, fileList) => {
                       inputForm.uploadPaymentVoucher = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.uploadPaymentVoucher = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="uploadPaymentVoucherArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        disFalse:false,//修改时根据状态不同
        statusFalse:false,//审核状态处新建都禁用
        method: '',
        visible: false,
        loading: false,
        taskImgArra: [],
        uploadPaymentVoucherArra: [],
        inputForm: {
          id: '',
          enterprise: {
            id: ''
          },
          enterpriseuser: {
            id: ''
          },
          taskTitle: '',
          taskNumber: '',
          taskContent: '',
          taskImg: '',
          commission: '',
          totalCommission: '',
          surplusCommission: '',
          receiveGroup: {
            id: ''
          },
          receiveGroupuser: {
            id: ''
          },
          isComplete: '',
          payment: '',
          uploadPaymentVoucher: '',
          auditStatus: '',
          advanceReceivableServiceFee: '',
          advanceReceivableTaxForehead: '',
          advanceReceivableRental: '',
          residueServiceFee: '',
          residueTaxForehead: '',
          residueRental: '',
          invoiceValoremTaxTotal: '',
          orderNumber: '',
          remarks: '',
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建pc任务详情`;
          this.statusFalse=false;
        } else if (method === 'edit') {
          this.title = '修改pc任务详情';
          this.statusFalse=true;
        } else if (method === 'view') {
          this.title = '查看pc任务详情'
          this.statusFalse=true;
        }
        this.taskImgArra = []
        this.uploadPaymentVoucherArra = []
        this.visible = true
        this.loading = false
        this.disFalse=false;
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/pctaskinformation/lhygPcTaskinformation/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.lhygPcTaskinformation);
              if (this.inputForm.auditStatus==3) {
                this.disFalse=true;
              }
              this.inputForm.taskImg.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.taskImgArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.inputForm.uploadPaymentVoucher.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.uploadPaymentVoucherArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          }
           
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            console.log(this.inputForm.enterprise.id,this.inputForm.enterpriseuser.id)
            if(this.inputForm.enterprise.id.length==0&&this.inputForm.enterpriseuser.id.length==0){
              this.$message.warning('企业或用户至少选择一个')
            }
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/pctaskinformation/lhygPcTaskinformation/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>